Stop using container api on GtkFlowBox
authorMatthias Clasen <mclasen@redhat.com>
Fri, 8 May 2020 03:24:58 +0000 (23:24 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 12 May 2020 02:21:39 +0000 (22:21 -0400)
GtkContainer is going away.

demos/gtk-demo/flowbox.c
gtk/a11y/gtkflowboxaccessible.c
tests/testflowbox.c

index 8340923be5eff10d41e2488d0460891607b3a633..25bfe36258c2aad776a85594b5a5d58c96e15c40 100644 (file)
@@ -737,7 +737,7 @@ do_flowbox (GtkWidget *do_widget)
       gtk_window_set_child (GTK_WINDOW (window), scrolled);
 
       for (i = 0; colors[i]; i++)
-        gtk_container_add (GTK_CONTAINER (flowbox), color_swatch_new (colors[i]));
+        gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), color_swatch_new (colors[i]), -1);
     }
 
   if (!gtk_widget_get_visible (window))
index d32a7f2db053128828dab7e0963c69c64b20ad31..5f03bf50876eaebb52ba5e11dadf88bb17112bac 100644 (file)
@@ -69,21 +69,23 @@ gtk_flow_box_accessible_add_selection (AtkSelection *selection,
                                        gint          idx)
 {
   GtkWidget *box;
-  GList *children;
   GtkWidget *child;
+  int pos;
 
   box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
   if (box == NULL)
     return FALSE;
 
-  children = gtk_container_get_children (GTK_CONTAINER (box));
-  child = g_list_nth_data (children, idx);
-  g_list_free (children);
-  if (child)
+  for (child = gtk_widget_get_first_child (box), pos = 0;
+       child != NULL && pos < idx;
+       child = gtk_widget_get_next_sibling (child), pos++) ;
+
+  if (child && pos == idx)
     {
       gtk_flow_box_select_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child));
       return TRUE;
     }
+
   return FALSE;
 }
 
@@ -92,21 +94,23 @@ gtk_flow_box_accessible_remove_selection (AtkSelection *selection,
                                           gint          idx)
 {
   GtkWidget *box;
-  GList *children;
   GtkWidget *child;
+  int pos;
 
   box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
   if (box == NULL)
     return FALSE;
 
-  children = gtk_container_get_children (GTK_CONTAINER (box));
-  child = g_list_nth_data (children, idx);
-  g_list_free (children);
-  if (child)
+  for (child = gtk_widget_get_first_child (box), pos = 0;
+       child != NULL && pos < idx;
+       child = gtk_widget_get_next_sibling (child), pos++) ;
+
+  if (child && pos == idx)
     {
       gtk_flow_box_unselect_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child));
       return TRUE;
     }
+
   return FALSE;
 }
 
index 84a1603b39ae0ae3e6063216daa5d392e7794abd..972392909feb359e537cd36f407c475855b4136e 100644 (file)
@@ -52,7 +52,7 @@ populate_flowbox_simple (GtkFlowBox *flowbox)
       gtk_frame_set_child (GTK_FRAME (frame), widget);
 
       g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (text), g_free);
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
 
       g_free (text);
     }
@@ -100,7 +100,7 @@ populate_flowbox_focus (GtkFlowBox *flowbox)
       if (i % 5 == 0)
         gtk_container_add (GTK_CONTAINER (box), gtk_switch_new ());
 
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
       if (!sensitive)
         gtk_widget_set_sensitive (gtk_widget_get_parent (frame), FALSE);
     }
@@ -115,7 +115,7 @@ populate_flowbox_buttons (GtkFlowBox *flowbox)
   for (i = 0; i < 50; i++)
     {
       widget = gtk_button_new_with_label ("Button");
-      gtk_container_add (GTK_CONTAINER (flowbox), widget);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), widget, -1);
       widget = gtk_widget_get_parent (widget);
       gtk_widget_set_can_focus (widget, FALSE);
     }
@@ -148,7 +148,7 @@ populate_flowbox_wrappy (GtkFlowBox *flowbox)
       gtk_label_set_width_chars (GTK_LABEL (widget), 10);
       g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (strings[i]), g_free);
 
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
     }
 }
 
@@ -185,17 +185,10 @@ populate_flowbox_images (GtkFlowBox *flowbox)
 static void
 populate_items (GtkFlowBox *flowbox)
 {
-  GList *children, *l;
-
-  /* Remove all children first */
-  children = gtk_container_get_children (GTK_CONTAINER (flowbox));
-  for (l = children; l; l = l->next)
-    {
-      GtkWidget *child = l->data;
+  GtkWidget *child;
 
-      gtk_container_remove (GTK_CONTAINER (flowbox), child);
-    }
-  g_list_free (children);
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (flowbox))))
+    gtk_flow_box_remove (flowbox, child);
 
   if (items_type == SIMPLE_ITEMS)
     populate_flowbox_simple (flowbox);